package org.example.feign_client1.config;

import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@Configuration
public class FeignConfig{
    @Bean
    public RequestInterceptor requestInterceptor(){

        return request->{
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
            HttpServletRequest request1 = requestAttributes.getRequest();
            Enumeration<String> headerNames = request1.getHeaderNames();
            System.out.println(headerNames);
            request.header("Authorization","bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiaHNtYWluX2ltIiwiaHNtYWluX25ld3MiLCJoc21haW5fYXR0ZW5kYW5jZSIsImhzbWFpbl9vcGVyYXRlIiwiaHNtYWluX2ludmVzdG1lbnQiLCJoc21haW5fSW5kdUNpdHkiLCJoc21haW5fY3VzdG9tZSIsImhzbWFpbl9wb2xpY3ltYXRjaCIsImhzbWFpbl93eV9wYXlzIiwiaHNtYWluX3RyYW5zYWN0aW9ucyIsImhzbWFpbi13eS1wcm9wZXJ0aWVzIiwiaHNhZG1pbl9sb2ciLCJoc21haW5fc3lzdGVtIiwiaHNtYWluX3JlbnRfY2FyIiwiaHNtYWluX3N1cnZleSIsImhzbWFpbl9nYXRld2F5IiwiaHNtYWluX3N1cGVydmlzaW9uIiwiaHNtYWluX3Jjd2Vic2l0ZSIsImhzbWFpbl9iYXNpYyIsImhzbWFpbl93eV9idXkiLCJoc21haW5fdmNhcmQiLCJoc21haW5fYXBwcyIsImhzbWFpbl9maW5hbmNpYWxzaGVsZiIsImhzbWFpbl93b3JrcmVwb3J0IiwiaHNtYWluX2ZpbGVzIiwiaHNtYWluX3BheSIsImhzbWFpbl9xaW5namlhIiwiaHNtYWluX3Nob3BwYXltZW50IiwiaHNtYWluX2VxdWlwbWVudG9t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